<template>
    <h3>理财信息添加</h3>
    <table>
        <tr>
            <td>项目名称</td>
            <td><input type="text" v-model="F_Name"></td>
        </tr>
        <tr>
            <td>年收益</td>
            <td><input type="text" v-model="F_Year"></td>
        </tr>
        <tr>
            <td>月收益</td>
            <td><input type="text" v-model="F_Month"></td>
        </tr>
        <tr>
            <td>最低金额</td>
            <td><input type="text" v-model="MinMoney"></td>
        </tr>
        <tr>
            <td>风险等级</td>
            <td>
                <input type="radio" name="Level" v-model="Level" value="低风险" checked>低风险
                <input type="radio" name="Level" v-model="Level" value="中风险">中风险
                <input type="radio" name="Level" v-model="Level" value="高风险">高风险
            </td>
        </tr>
        <tr>
            <td>利息</td>
            <td>
                <select v-model="I_Id">
                    <option value="0">请选择</option>
                    <option v-for="item in str" :key="item.I_Id" :value="item.I_Id">{{ item.I_Inverest }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2"><button @click="Add">添加</button></td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import axios from 'axios';
//定义字段
const F_Name = ref('');
const F_Year = ref('');
const F_Month = ref('');
const MinMoney = ref();
const Level = ref();
const I_Id = ref(0);

//绑定下拉
const str = ref([]);
onMounted(() => {
    axios.get('http://localhost:53436/api/Financing/BindInverest')
        .then(res => {
            str.value = res.data;
        })
        .catch(error => {
            console.log(error);
        })
})

const Add = () => {
    axios.post('http://localhost:53436/api/Financing/AddFinancing', {
        F_Name: F_Name.value,
        F_Year: F_Year.value,
        F_Month: F_Month.value,
        MinMoney: MinMoney.value,
        Level: Level.value,
        I_Id: I_Id.value
    })
        .then(res => {
            if (res.data > 0) {
                alert("添加成功")
                go();
            }
            else {
                alert("添加失败")
                return;
            }
        })
}
import { useRouter } from 'vue-router';
const router = useRouter();
const go = () => {
    router.push('/Show');
}
</script>